package com.carlinfo.stu_ques.common.util;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;

public class FileUtil implements Serializable
{
	public boolean writeFile(OutputStream feil,Object obj) 
	{
		ObjectOutputStream fos = null;
		try
		{
			BufferedOutputStream oos = new BufferedOutputStream(feil);
			fos = new ObjectOutputStream(oos);
			fos.writeObject(obj);
			/*控水管*/
			fos.flush();
			return true;
		} catch (IOException e)
		{
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
		}finally
		{
			try
			{
				if(fos != null) 
				{
					/*关水管*/
					fos.close();
					fos = null;
				}
			} catch (Exception e)
			{
				e.printStackTrace();
			}
		}
		return false;
	}
	
	
	
	public Object  readFile(InputStream file)
	{
		ObjectInputStream fis = null;
		try
		{
			BufferedInputStream ois = new BufferedInputStream(file);
			fis = new ObjectInputStream(ois);
			return fis.readObject();
		}catch (IOException e)
		{
			e.printStackTrace();
		}catch (Exception e)
		{
			e.printStackTrace();
		}finally 
		{
			try
			{
				if(fis != null)
				{
					/* 关水管 */
					fis.close();
					fis =null;
				}
			} catch (IOException e)
			{
				e.printStackTrace();
			}
		}
		return null;
	}
}
